package com.cy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@FeignClient(name = "nacos-provider")
//@FeignClient的内部为服务名
//@FeignClient描述的接口,底层会为其创建实现类
interface ConsumerHttpApi {
    @GetMapping("/provider/echo/{string}")
//注意feign中的@PathVariable要指定value的值，不然报错
    public String doEcho(@PathVariable(value = "string") String string);
}

@RestController
@RequestMapping("/consumer/feign/")
public class Feign方式调用ConsumerController {
    @Autowired
    private ConsumerHttpApi consumerHttpApi;

    //http://localhost:8090/consumer/feign/hello
    @GetMapping("{string}")
    public String doEcho(@PathVariable String string) {
        //通过feign的方式来调用url,省去手写的url代码
        return consumerHttpApi.doEcho(string);
    }

}
